﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Marbles.Core.Connectors;
using System.Data;

namespace Marbles.Core.Content.Sites
{
    public class SiteDefinitionCollection : ICollection<SiteDefinition>
    {
        public SiteDefinition this[int index] { get { return items[index]; } }

        private List<SiteDefinition> items = null;

        public SiteDefinitionCollection()
        {
            items = new List<SiteDefinition>();
            Clear();
            DataConnection dbc = new DataConnection();
            Command cmd = new Command("SELECT * FROM sites ORDER BY title ASC");
            
            foreach (DataRow dr in dbc.FetchDataTable(cmd).Rows)
            {
                items.Add(new SiteDefinition(dr));
            }
        }

        public void Add(SiteDefinition item)
        {
            items.Add(item);
        }

        public void Clear()
        {
            items.Clear();
        }

        public bool Contains(SiteDefinition item)
        {
            return items.Contains(item);
        }

        public void CopyTo(SiteDefinition[] array, int arrayIndex)
        {
            items.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return items.Count; }
        }

        public bool IsReadOnly
        {
            get { return true; }
        }

        public bool Remove(SiteDefinition item)
        {
            return items.Remove(item);
        }

        public IEnumerator<SiteDefinition> GetEnumerator()
        {
            return items.GetEnumerator();
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return items.GetEnumerator();
        }
    }
}
